{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "96af610e",
   "metadata": {},
   "source": [
    "# SciPy中的常量\n",
    "由于SciPy更专注于科学的实现，它提供了许多内置的科学常量。\n",
    "\n",
    "当你从事数据科学工作时，这些常量会很有帮助。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "d56c75b3",
   "metadata": {},
   "outputs": [],
   "source": [
    "from scipy import constants"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "6b726a21",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3.141592653589793\n"
     ]
    }
   ],
   "source": [
    "print(constants.pi)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b04ddf9c",
   "metadata": {},
   "source": [
    "# 常量单位\n",
    "使用dir()函数可以看到常量模块下所有单位的列表。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "1353cea2",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['Avogadro', 'Boltzmann', 'Btu', 'Btu_IT', 'Btu_th', 'ConstantWarning', 'G', 'Julian_year', 'N_A', 'Planck', 'R', 'Rydberg', 'Stefan_Boltzmann', 'Wien', '__all__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', '_obsolete_constants', 'acre', 'alpha', 'angstrom', 'arcmin', 'arcminute', 'arcsec', 'arcsecond', 'astronomical_unit', 'atm', 'atmosphere', 'atomic_mass', 'atto', 'au', 'bar', 'barrel', 'bbl', 'blob', 'c', 'calorie', 'calorie_IT', 'calorie_th', 'carat', 'centi', 'codata', 'constants', 'convert_temperature', 'day', 'deci', 'degree', 'degree_Fahrenheit', 'deka', 'dyn', 'dyne', 'e', 'eV', 'electron_mass', 'electron_volt', 'elementary_charge', 'epsilon_0', 'erg', 'exa', 'exbi', 'femto', 'fermi', 'find', 'fine_structure', 'fluid_ounce', 'fluid_ounce_US', 'fluid_ounce_imp', 'foot', 'g', 'gallon', 'gallon_US', 'gallon_imp', 'gas_constant', 'gibi', 'giga', 'golden', 'golden_ratio', 'grain', 'gram', 'gravitational_constant', 'h', 'hbar', 'hectare', 'hecto', 'horsepower', 'hour', 'hp', 'inch', 'k', 'kgf', 'kibi', 'kilo', 'kilogram_force', 'kmh', 'knot', 'lambda2nu', 'lb', 'lbf', 'light_year', 'liter', 'litre', 'long_ton', 'm_e', 'm_n', 'm_p', 'm_u', 'mach', 'mebi', 'mega', 'metric_ton', 'micro', 'micron', 'mil', 'mile', 'milli', 'minute', 'mmHg', 'mph', 'mu_0', 'nano', 'nautical_mile', 'neutron_mass', 'nu2lambda', 'ounce', 'oz', 'parsec', 'pebi', 'peta', 'physical_constants', 'pi', 'pico', 'point', 'pound', 'pound_force', 'precision', 'proton_mass', 'psi', 'pt', 'short_ton', 'sigma', 'slinch', 'slug', 'speed_of_light', 'speed_of_sound', 'stone', 'survey_foot', 'survey_mile', 'tebi', 'tera', 'test', 'ton_TNT', 'torr', 'troy_ounce', 'troy_pound', 'u', 'unit', 'value', 'week', 'yard', 'year', 'yobi', 'yotta', 'zebi', 'zepto', 'zero_Celsius', 'zetta']\n"
     ]
    }
   ],
   "source": [
    "print(dir(constants))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d5023079",
   "metadata": {},
   "source": [
    "# 单位类别\n",
    "单位被置于这些类别之下。\n",
    "\n",
    "公制 二进制 质量 角度\n",
    "\n",
    "时间 长度 压力 体积\n",
    "\n",
    "速度 温度 能量 功率 力\n",
    "## 长度\n",
    "返回指定的单位，以米为单位（例如，centi返回0.01）。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "b088925a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1e+24\n",
      "1e+21\n",
      "1e+18\n",
      "1000000000000000.0\n",
      "1000000000000.0\n",
      "1000000000.0\n",
      "1000000.0\n",
      "1000.0\n",
      "100.0\n",
      "10.0\n",
      "0.1\n",
      "0.01\n",
      "0.001\n",
      "1e-06\n",
      "1e-09\n",
      "1e-12\n",
      "1e-15\n",
      "1e-18\n",
      "1e-21\n"
     ]
    }
   ],
   "source": [
    "print(constants.yotta)    #1e+24\n",
    "print(constants.zetta)    #1e+21\n",
    "print(constants.exa)      #1e+18\n",
    "print(constants.peta)     #1000000000000000.0\n",
    "print(constants.tera)     #1000000000000.0\n",
    "print(constants.giga)     #1000000000.0\n",
    "print(constants.mega)     #1000000.0\n",
    "print(constants.kilo)     #1000.0\n",
    "print(constants.hecto)    #100.0\n",
    "print(constants.deka)     #10.0\n",
    "print(constants.deci)     #0.1\n",
    "print(constants.centi)    #0.01\n",
    "print(constants.milli)    #0.001\n",
    "print(constants.micro)    #1e-06\n",
    "print(constants.nano)     #1e-09\n",
    "print(constants.pico)     #1e-12\n",
    "print(constants.femto)    #1e-15\n",
    "print(constants.atto)     #1e-18\n",
    "print(constants.zepto)    #1e-21"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "33459302",
   "metadata": {},
   "source": [
    "## 二进制单位\n",
    "返回以字节为单位的指定单位（例如，kibi返回1024）。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "5aea033f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1024\n",
      "1048576\n",
      "1073741824\n",
      "1099511627776\n",
      "1125899906842624\n",
      "1152921504606846976\n",
      "1180591620717411303424\n",
      "1208925819614629174706176\n"
     ]
    }
   ],
   "source": [
    "print(constants.kibi)    #1024\n",
    "print(constants.mebi)    #1048576\n",
    "print(constants.gibi)    #1073741824\n",
    "print(constants.tebi)    #1099511627776\n",
    "print(constants.pebi)    #1125899906842624\n",
    "print(constants.exbi)    #1152921504606846976\n",
    "print(constants.zebi)    #1180591620717411303424\n",
    "print(constants.yobi)    #1208925819614629174706176"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "612f036a",
   "metadata": {},
   "source": [
    "## 质量\n",
    "返回以公斤为单位的指定单位（例如，克返回0.001）。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "700ca190",
   "metadata": {},
   "outputs": [],
   "source": [
    "print(constants.gram)        #0.001\n",
    "print(constants.metric_ton)  #1000.0\n",
    "print(constants.grain)       #6.479891e-05\n",
    "print(constants.lb)          #0.45359236999999997\n",
    "print(constants.pound)       #0.45359236999999997\n",
    "print(constants.oz)          #0.028349523124999998\n",
    "print(constants.ounce)       #0.028349523124999998\n",
    "print(constants.stone)       #6.3502931799999995\n",
    "print(constants.long_ton)    #1016.0469088\n",
    "print(constants.short_ton)   #907.1847399999999\n",
    "print(constants.troy_ounce)  #0.031103476799999998\n",
    "print(constants.troy_pound)  #0.37324172159999996\n",
    "print(constants.carat)       #0.0002\n",
    "print(constants.atomic_mass) #1.66053904e-27\n",
    "print(constants.m_u)         #1.66053904e-27\n",
    "print(constants.u)           #1.66053904e-27"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d7503622",
   "metadata": {},
   "source": [
    "## 角度\n",
    "返回以弧度为单位的指定单位（例如，度返回0.017453292519943295）。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "beb88d10",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.017453292519943295\n",
      "0.0002908882086657216\n",
      "0.0002908882086657216\n",
      "4.84813681109536e-06\n",
      "4.84813681109536e-06\n"
     ]
    }
   ],
   "source": [
    "print(constants.degree)     #0.017453292519943295\n",
    "print(constants.arcmin)     #0.0002908882086657216\n",
    "print(constants.arcminute)  #0.0002908882086657216\n",
    "print(constants.arcsec)     #4.84813681109536e-06\n",
    "print(constants.arcsecond)  #4.84813681109536e-06"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "93fd561e",
   "metadata": {},
   "source": [
    "## 时间\n",
    "返回指定的单位，以秒为单位（例如，小时返回3600.0）。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "85ec2498",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "60.0\n",
      "3600.0\n",
      "86400.0\n",
      "604800.0\n",
      "31536000.0\n",
      "31557600.0\n"
     ]
    }
   ],
   "source": [
    "print(constants.minute)      #60.0\n",
    "print(constants.hour)        #3600.0\n",
    "print(constants.day)         #86400.0\n",
    "print(constants.week)        #604800.0\n",
    "print(constants.year)        #31536000.0\n",
    "print(constants.Julian_year) #31557600.0"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4160f2d4",
   "metadata": {},
   "source": [
    "## 长度\n",
    "返回指定的单位，以米为单位（例如，海里返回1852.0）。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "2ddf10c2",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.0254\n",
      "0.30479999999999996\n",
      "0.9143999999999999\n",
      "1609.3439999999998\n",
      "2.5399999999999997e-05\n",
      "0.00035277777777777776\n",
      "0.00035277777777777776\n",
      "0.3048006096012192\n",
      "1609.3472186944373\n",
      "1852.0\n",
      "1e-15\n",
      "1e-10\n",
      "1e-06\n",
      "149597870700.0\n",
      "149597870700.0\n",
      "9460730472580800.0\n",
      "3.085677581491367e+16\n"
     ]
    }
   ],
   "source": [
    "print(constants.inch)              #0.0254\n",
    "print(constants.foot)              #0.30479999999999996\n",
    "print(constants.yard)              #0.9143999999999999\n",
    "print(constants.mile)              #1609.3439999999998\n",
    "print(constants.mil)               #2.5399999999999997e-05\n",
    "print(constants.pt)                #0.00035277777777777776\n",
    "print(constants.point)             #0.00035277777777777776\n",
    "print(constants.survey_foot)       #0.3048006096012192\n",
    "print(constants.survey_mile)       #1609.3472186944373\n",
    "print(constants.nautical_mile)     #1852.0\n",
    "print(constants.fermi)             #1e-15\n",
    "print(constants.angstrom)          #1e-10\n",
    "print(constants.micron)            #1e-06\n",
    "print(constants.au)                #149597870691.0\n",
    "print(constants.astronomical_unit) #149597870691.0\n",
    "print(constants.light_year)        #9460730472580800.0\n",
    "print(constants.parsec)            #3.0856775813057292e+16"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "af59c8f1",
   "metadata": {},
   "source": [
    "## 压力\n",
    "返回以帕斯卡为单位的指定单位（例如：psi返回6894.757293168361）。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "a3acc12d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "101325.0\n",
      "101325.0\n",
      "100000.0\n",
      "133.32236842105263\n",
      "133.32236842105263\n",
      "6894.757293168361\n"
     ]
    }
   ],
   "source": [
    "print(constants.atm)         #101325.0\n",
    "print(constants.atmosphere)  #101325.0\n",
    "print(constants.bar)         #100000.0\n",
    "print(constants.torr)        #133.32236842105263\n",
    "print(constants.mmHg)        #133.32236842105263\n",
    "print(constants.psi)         #6894.757293168361"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9c8a7e7a",
   "metadata": {},
   "source": [
    "## 面积\n",
    "返回以平方米为单位的指定单位（例如，公顷返回10000.0）。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "207b2ec0",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "10000.0\n",
      "4046.8564223999992\n"
     ]
    }
   ],
   "source": [
    "print(constants.hectare) #10000.0\n",
    "print(constants.acre)    #4046.8564223999992"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ab35036d",
   "metadata": {},
   "source": [
    "## 体积\n",
    "返回以立方米为单位的指定单位（例如，升返回0.001）。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "759452ba",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.001\n",
      "0.001\n",
      "0.0037854117839999997\n",
      "0.0037854117839999997\n",
      "0.00454609\n",
      "2.9573529562499998e-05\n",
      "2.9573529562499998e-05\n",
      "2.84130625e-05\n",
      "0.15898729492799998\n",
      "0.15898729492799998\n"
     ]
    }
   ],
   "source": [
    "print(constants.liter)            #0.001\n",
    "print(constants.litre)            #0.001\n",
    "print(constants.gallon)           #0.0037854117839999997\n",
    "print(constants.gallon_US)        #0.0037854117839999997\n",
    "print(constants.gallon_imp)       #0.00454609\n",
    "print(constants.fluid_ounce)      #2.9573529562499998e-05\n",
    "print(constants.fluid_ounce_US)   #2.9573529562499998e-05\n",
    "print(constants.fluid_ounce_imp)  #2.84130625e-05\n",
    "print(constants.barrel)           #0.15898729492799998\n",
    "print(constants.bbl)              #0.15898729492799998"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "205dfc7f",
   "metadata": {},
   "source": [
    "## 速度\n",
    "返回指定的单位，单位为米/秒（例如，音速返回340.5）。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "2c8640fd",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.2777777777777778\n",
      "0.44703999999999994\n",
      "340.5\n",
      "340.5\n",
      "0.5144444444444445\n"
     ]
    }
   ],
   "source": [
    "print(constants.kmh)            #0.2777777777777778\n",
    "print(constants.mph)            #0.44703999999999994\n",
    "print(constants.mach)           #340.5\n",
    "print(constants.speed_of_sound) #340.5\n",
    "print(constants.knot)           #0.5144444444444445"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f43f91a4",
   "metadata": {},
   "source": [
    "## 温度\n",
    "返回指定的开尔文单位（如零摄氏度返回273.15）。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "2930cd2c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "273.15\n",
      "0.5555555555555556\n"
     ]
    }
   ],
   "source": [
    "print(constants.zero_Celsius)      #273.15\n",
    "print(constants.degree_Fahrenheit) #0.5555555555555556"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5da714be",
   "metadata": {},
   "source": [
    "## 能量\n",
    "返回以焦耳为单位的指定单位（如卡路里返回4.184）。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "1749790b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1.602176634e-19\n",
      "1.602176634e-19\n",
      "4.184\n",
      "4.184\n",
      "4.1868\n",
      "1e-07\n",
      "1055.05585262\n",
      "1055.05585262\n",
      "1054.3502644888888\n",
      "4184000000.0\n"
     ]
    }
   ],
   "source": [
    "print(constants.eV)            #1.6021766208e-19\n",
    "print(constants.electron_volt) #1.6021766208e-19\n",
    "print(constants.calorie)       #4.184\n",
    "print(constants.calorie_th)    #4.184\n",
    "print(constants.calorie_IT)    #4.1868\n",
    "print(constants.erg)           #1e-07\n",
    "print(constants.Btu)           #1055.05585262\n",
    "print(constants.Btu_IT)        #1055.05585262\n",
    "print(constants.Btu_th)        #1054.3502644888888\n",
    "print(constants.ton_TNT)       #4184000000.0"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8a90d43e",
   "metadata": {},
   "source": [
    "## 功率\n",
    "返回以瓦为单位的指定单位（例如，马力返回745.6998715822701）。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "fef51478",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "745.6998715822701\n",
      "745.6998715822701\n"
     ]
    }
   ],
   "source": [
    "print(constants.hp)         #745.6998715822701\n",
    "print(constants.horsepower) #745.6998715822701"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a87e88cf",
   "metadata": {},
   "source": [
    "## 力\n",
    "返回指定的牛顿单位（例如，千克力返回9.80665）。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "1e79aa9f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1e-05\n",
      "1e-05\n",
      "4.4482216152605\n",
      "4.4482216152605\n",
      "9.80665\n",
      "9.80665\n"
     ]
    }
   ],
   "source": [
    "print(constants.dyn)             #1e-05\n",
    "print(constants.dyne)            #1e-05\n",
    "print(constants.lbf)             #4.4482216152605\n",
    "print(constants.pound_force)     #4.4482216152605\n",
    "print(constants.kgf)             #9.80665\n",
    "print(constants.kilogram_force)  #9.80665"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.10"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": true
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
